// 社团模型
const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const User = require('./User');

const Association = sequelize.define('Association', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  name: {
    type: DataTypes.STRING(100),
    allowNull: false,
    unique: true,
    comment: '社团名称'
  },
  logo: {
    type: DataTypes.STRING(255),
    allowNull: true,
    comment: '社团Logo'
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true,
    comment: '社团描述'
  },
  category: {
    type: DataTypes.STRING(50),
    allowNull: false,
    comment: '社团分类'
  },
  level: {
    type: DataTypes.STRING(20),
    allowNull: true,
    comment: '社团级别'
  },
  presidentId: {
    type: DataTypes.INTEGER,
    allowNull: true,
    references: {
      model: User,
      key: 'id'
    },
    comment: '社长用户ID'
  },
  contactPhone: {
    type: DataTypes.STRING(20),
    allowNull: true,
    comment: '联系电话'
  },
  contactEmail: {
    type: DataTypes.STRING(100),
    allowNull: true,
    comment: '联系邮箱'
  },
  memberCount: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 0,
    comment: '成员数量'
  },
  establishDate: {
    type: DataTypes.DATE,
    allowNull: true,
    comment: '成立日期'
  },
  status: {
    type: DataTypes.INTEGER,
    allowNull: false,
    defaultValue: 1,
    comment: '状态 1:正常 2:审核中 3:已下架 4:已禁用'
  },
  createdAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW
  },
  updatedAt: {
    type: DataTypes.DATE,
    allowNull: false,
    defaultValue: DataTypes.NOW
  }
}, {
  tableName: 'associations',
  timestamps: true,
  charset: 'utf8mb4',
  collate: 'utf8mb4_unicode_ci'
});

// 关联关系
Association.belongsTo(User, { as: 'president', foreignKey: 'presidentId' });

module.exports = Association;